package com.army.modules.host.controller;


import com.army.common.properties.FileProperties;
import com.army.modules.host.job.FileToData;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-12-20
 */
@Controller
@Slf4j
@AllArgsConstructor
public class HostWaterController {
    private final FileToData fileToData;
    private final FileProperties fileProperties;
    @RequestMapping("/host")
    @ResponseBody
    public void FileToData(){

        //初始化任务参数
        JobParameters jobParameters = new JobParametersBuilder()

                .addString("receiveFilePath",fileProperties.getReceiveFilePath())
                .addDate("date", new Date())
                .toJobParameters();
        try {
            fileToData.run(jobParameters);
            System.out.println("jobParameters = " + jobParameters);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

